package cn.alone.user.controller;

import cn.alone.basic.util.AjaxResult;
import cn.alone.user.domain.Logininfo;
import cn.alone.user.service.ILogininfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/logininfo")
@Api(tags = "登录信息接口",description = "登录信息接口详细描述")
public class LogininfoController {
    @Autowired
    private ILogininfoService logininfoService;

    //新增或修改   POST
    @PostMapping("/save")
    @ApiOperation(value = "登录信息添加或修改",notes = "如果有id就是修改否则就是添加")
    public AjaxResult addOrUpdate(@RequestBody Logininfo logininfo){
        try {
            if (logininfo.getId() == null) {
                logininfoService.add(logininfo);
            } else {
                logininfoService.update(logininfo);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,稍后重试");
        }
    }
    
    //删除    DELETE
    @DeleteMapping("/{id}")  // http://localhost:8080/dept/1
    public AjaxResult removeById(@PathVariable("id") Long id){
        try {
            logininfoService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me()
                    .setSuccess(false)
                    .setMessage("系统繁忙,稍后重试");
        }
    }

}
